package com.jiawa.train.business.config;

import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
@ComponentScan("com.jiawa")
@Slf4j
@MapperScan("com.jiawa.train.business.mapper")
@EnableFeignClients(basePackages = "com.jiawa.train.business.feign")
@EnableCaching
@ImportAutoConfiguration(RocketMQAutoConfiguration.class)
public class BusinessApplication {

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(BusinessApplication.class);
        ConfigurableEnvironment environment = app.run(args).getEnvironment();
        log.info("启动成功!");
        log.info("启动地址为:\thttps://127.0.0.1:{}", environment.getProperty("server.port"));
        intiFlowRules();
    }

    private static void intiFlowRules(){
        List<FlowRule> flowRules = new ArrayList<>();
        FlowRule flowRule = new FlowRule();
        flowRule.setResource("doConfirm");
        flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
        flowRule.setCount(10);
        flowRules.add(flowRule);
    }

}
